Skip to content

Added support for Arbitrary for fuzzing#14

Open
LucaCappelletti94 wants to merge 3 commits intoisdaniel:mainfrom
LucaCappelletti94:feat/add-arbitrary-support
Open

Added support for Arbitrary for fuzzing#14
LucaCappelletti94 wants to merge 3 commits intoisdaniel:mainfrom
LucaCappelletti94:feat/add-arbitrary-support

Conversation

@LucaCappelletti94
Copy link
Contributor

Pretty straighforward PR adding an implementation of Arbitrary. I need it for fuzz random structured pgprotocols.

@gemini-code-assist
Copy link

Summary of Changes

Hello @LucaCappelletti94, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces comprehensive support for fuzz testing by integrating the arbitrary crate. It allows for the generation of random, well-formed PostgreSQL logical replication messages and associated data structures, which is crucial for robust testing and discovering edge cases in protocol handling. The changes are encapsulated within an optional feature, maintaining a lean dependency tree for standard builds.

Highlights

  • Fuzzing Support: Added the arbitrary crate as an optional dependency to enable fuzzing capabilities for data structures representing PostgreSQL logical replication protocols.
  • Arbitrary Trait Implementations: Implemented the arbitrary::Arbitrary trait for key protocol-related enums and structs, including MessageType, LogicalReplicationMessage, ColumnData, CachePadded, and ReplicaIdentity, allowing them to be randomly generated for testing.
  • Conditional Compilation: All arbitrary implementations and dependencies are guarded by a new arbitrary feature, ensuring that the fuzzing-specific code is only compiled when explicitly enabled.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • Cargo.lock
    • Added arbitrary and derive_arbitrary packages and their respective checksums and dependencies.
  • Cargo.toml
    • Added arbitrary as an optional dependency with the derive feature.
    • Defined a new arbitrary feature that enables the arbitrary dependency.
  • src/protocol.rs
    • Implemented arbitrary::Arbitrary for MessageType to generate random message types.
    • Implemented arbitrary::Arbitrary for LogicalReplicationMessage to generate random logical replication messages with arbitrary field values.
    • Added #[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] to ColumnInfo, TupleData, and RelationInfo for automatic Arbitrary derivation.
    • Implemented arbitrary::Arbitrary for ColumnData to generate random column data types (null, unchanged, text, binary).
  • src/types.rs
    • Implemented arbitrary::Arbitrary for the generic CachePadded<T> struct.
    • Implemented arbitrary::Arbitrary for ReplicaIdentity to generate random replica identity types.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@LucaCappelletti94 LucaCappelletti94 marked this pull request as ready for review February 11, 2026 01:37
Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds support for fuzzing by implementing the Arbitrary trait for various protocol message types, which is a valuable addition for improving the robustness of the parsing logic. The changes are generally well-implemented. My review includes a few suggestions to make the code more maintainable and idiomatic by leveraging features from the arbitrary crate, such as its derive macro and choose method, which will simplify the code and make it less brittle to future changes.

@codecov
Copy link

codecov bot commented Feb 11, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (main@d3fcb12). Learn more about missing BASE report.

Additional details and impacted files
@@           Coverage Diff           @@
##             main      #14   +/-   ##
=======================================
  Coverage        ?   64.10%           
=======================================
  Files           ?        8           
  Lines           ?     4608           
  Branches        ?        0           
=======================================
  Hits            ?     2954           
  Misses          ?     1654           
  Partials        ?        0           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI added a commit that referenced this pull request Feb 11, 2026
Co-authored-by: isdaniel <9159452+isdaniel@users.noreply.github.com>
Copilot AI added a commit that referenced this pull request Feb 11, 2026
Co-authored-by: isdaniel <9159452+isdaniel@users.noreply.github.com>
Copilot AI added a commit that referenced this pull request Feb 11, 2026
Co-authored-by: isdaniel <9159452+isdaniel@users.noreply.github.com>
Copilot AI added a commit that referenced this pull request Feb 11, 2026
Co-authored-by: isdaniel <9159452+isdaniel@users.noreply.github.com>
Copilot AI added a commit that referenced this pull request Feb 11, 2026
Co-authored-by: isdaniel <9159452+isdaniel@users.noreply.github.com>
Copilot AI added a commit that referenced this pull request Feb 11, 2026
@isdaniel
Copy link
Owner

Hi @LucaCappelletti94 thank you for your PR, I didn't use arbitrary crate lib before, as I reviewed from https://github.com/rust-fuzz/arbitrary github readme and docs https://docs.rs/arbitrary/latest/arbitrary/, as my understanding it's generally intended to be used with random fuzzers structured.

however, could you share more detail or used case that benefit for this lib that we really need that? so far, I haven't come up with any scenario where it would be necessary to provide a fuzzing API to the client.

@LucaCappelletti94
Copy link
Contributor Author

Basically, I wrote a crate for the SQLite patchset format, which I directly attach on top of a logical stream. My crate needs to be solid and able to handle any possible input of your crate without crashing, hence the fuzzer.

Specifically, I use honggfuzz.

@isdaniel
Copy link
Owner

Hi @LucaCappelletti94 can we use arbitrary combine pg-walstream crate instead of modified that internally? because I don't want to introduce any code which don't relate to PostgreSQL replication protocol implement in this lib.

here is the example for Arbitrary for fuzzing #19

@LucaCappelletti94
Copy link
Contributor Author

In my uses cases, I found that the simplest possible solution was:

Of course, this causes a MASSIVE amount of tests to be discarded, and that is what the structured Arbitrary impl should avoid.

I will study a bit more in details the proposed impl and review it asap.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants